#ifndef __SCNS_TOUCH_SCREEN_H__
#define __SCNS_TOUCH_SCREEN_H__

#include "ScnsConfig.h"

#if defined(SCNS_TOUCH_SCREEN_ENABLE)&&SCNS_TOUCH_SCREEN_ENABLE==1

#include "ScnsYing.h"
#include "ScnsBspTouchScreen.h"
#include "ScnsKey.h"
#include "ScnsImage.h"
#include "ScnsLcd.h"

typedef struct
{
    Point p;
}ScnsTouchScreenSource;

typedef enum
{
    SCNS_TOUCH_SCREEN_BUTTON_RECTANGLE,
    SCNS_TOUCH_SCREEN_BUTTON_CIRCLE,
    SCNS_TOUCH_SCREEN_BUTTON_IMAGE,
}ScnsTouchScreenButtonShape;

typedef struct
{
    ScnsTouchScreenButtonShape shape;
    ScnsKeyEnum key;
    union
    {
        struct
        {
            Point plu;
            int16 w,h;
        }rectangle;
        struct
        {
            Point plu;
            int16 r;
        }circle;
#if defined(SCNS_IMAGE_ENABLE)&&SCNS_IMAGE_ENABLE==1
        struct
        {
            Point plu;
            const ScnsImage*image;
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
            uint8 displayMerge;
#endif
        }image;
#endif
    }shapeData;
}ScnsTouchScreenButton;

#define ScnsTouchScreenButtonCircle(KEY,X,Y,R)          {.key=(KEY),.shape=SCNS_TOUCH_SCREEN_BUTTON_CIRCLE,.shapeData.circle={.plu={.x=(X),.y=(Y)},.r=(R)}}
#define ScnsTouchScreenButtonRectangle(KEY,X,Y,W,H)     {.key=(KEY),.shape=SCNS_TOUCH_SCREEN_BUTTON_RECTANGLE,.shapeData.rectangle={.plu={.x=(X),.y=(Y)},.w=(W),.h=(H)}}
#if defined(SCNS_IMAGE_ENABLE)&&SCNS_IMAGE_ENABLE==1
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
#define ScnsTouchScreenButtonImage(KEY,X,Y,IMG,DM)      {.key=(KEY),.shape=SCNS_TOUCH_SCREEN_BUTTON_IMAGE,.shapeData.image={.plu={.x=(X),.y=(Y)},.image=(IMG),.displayMerge=(DM)}}
#else
#define ScnsTouchScreenButtonImage(KEY,X,Y,IMG,DM)      {.key=(KEY),.shape=SCNS_TOUCH_SCREEN_BUTTON_IMAGE,.shapeData.image={.plu={.x=(X),.y=(Y)},.image=(IMG)}}
#endif
#endif

extern ScnsStatus scnsTouchScreenInit(void);
extern void scnsTouchScreenUpdate(ScnsTouchScreenSource source);
extern void scnsTouchScreenScan(void);
extern ScnsTouchScreenButtonId scnsTouchScreenAddButton(const ScnsTouchScreenButton*button);
extern ScnsTouchScreenButtonId scnsTouchScreenGetButtonId(const ScnsTouchScreenButton*button);
extern void scnsTouchScreenRemoveButton(ScnsTouchScreenButtonId id);
extern void scnsTouchScreenClean(void);
#define scnsTouchScreenIsButtonIdAvailable(id)  (((ScnsTouchScreenButtonId)-1)!=(id))
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1
extern void scnsTouchScreenDisplayButtonAll(ScnsLcdLayer layN,uint8 force);
extern void scnsTouchScreenDisplayButton(ScnsLcdLayer layN,const ScnsTouchScreenButton*button,ScnsLcdColor color);
#endif

#endif
#endif
